﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TMS_Master.DTO.Owner;
using TMS_Master.Personnel_module;
using Volo.Abp.Application.Dtos;
using Volo.Abp.Application.Services;
using Volo.Abp.Domain.Repositories;

namespace TMS_Master
{
    public class OwnerService : CrudAppService
        <Owner,
        OwnerDTO,
        Guid,
        PagedAndSortedResultRequestDto,
        OwnerDTOText>,
        IOwnerService
    {
        public readonly IRepository<Owner, Guid> tMSApp;
        public OwnerService(IRepository<Owner, Guid> _tMSApp) : base(_tMSApp)
        {
            tMSApp = _tMSApp;
        }
        /// <summary>
        /// 新增
        /// </summary>
        /// <param name="Staff"></param>
        /// <returns></returns>
        public async Task<int> AddOwner(OwnerDTO Owner)
        {
            Owner Add = ObjectMapper.Map<OwnerDTO, Owner>(Owner);
            await tMSApp.InsertAsync(Add);
            return 1;
        }

        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        public async Task DelOwner(Guid Id)
        {
            await tMSApp.DeleteAsync(Id);
        }
        /// <summary>
        /// 反填
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        public async Task<OwnerDTO> FanOwner(Guid Id)
        {
            Owner b = await tMSApp.GetAsync(Id);
            OwnerDTO fan = ObjectMapper.Map<Owner, OwnerDTO>(b);
            return fan;
        }

        /// <summary>
        /// 查询
        /// </summary>
        /// <returns></returns>
        public async Task<List<OwnerDTO>> GetOwner()
        {
            List<Owner> p = await tMSApp.ToListAsync();
            List<Owner> becomes = p;
            List<OwnerDTO> OwnerDTOs = ObjectMapper.Map<List<Owner>, List<OwnerDTO>>(becomes);
            return OwnerDTOs;

        }
        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="become"></param>
        /// <returns></returns>
        public async Task<int> UptOwner(OwnerDTO become)
        {
            Owner e = await tMSApp.GetAsync(become.Id);
            e.ContractTitle = become.ContractTitle;
            return 1;
        }
    }
}
